﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ChengNet.StrongCaml.Examples
{
    class Program
    {
        static void Main(string[] args) {
            var camlQuery =
                Caml.Query(
                    Caml.Where(
                        Caml.And(
                            Caml.And(
                                Caml.Lt(
                                    Caml.FieldRef("Date"),
                                    Caml.Value(DateTime.Now, TimeValue.Include)
                                ),
                                Caml.Geq(
                                    Caml.FieldRef("Date"),
                                    Caml.Value(
                                        Caml.Today(-14)
                                    )
                                )
                            ),
                            Caml.Or(
                                Caml.Eq(
                                    Caml.FieldRef("AssignedTo"),
                                    Caml.Value<ValueType.Integer>(
                                        Caml.UserID()
                                    )
                                ),
                                Caml.Eq(
                                    Caml.FieldRef("Descrip"),
                                    Caml.Value<ValueType.Lookup>(13)
                                )
                            )
                        )
                    ),
                    Caml.OrderBy(
                        Caml.FieldRef("Title", SortOrder.Descending),
                        Caml.FieldRef("Author")
                    )
                );

            string implicitStringQuery = camlQuery;
            var prettyQuery = XDocument.Parse(camlQuery.ToString()).ToString();
            Console.WriteLine(prettyQuery);
            Console.ReadLine();
        }
    }
}
